package com.xiaoshuidi.cloud.module.rooms.valid;

import com.xiaoshuidi.cloud.framework.filings.core.enums.CodeTypeEnum;
import com.xiaoshuidi.cloud.framework.filings.core.enums.DecorationLevelEnum;
import com.xiaoshuidi.cloud.framework.filings.core.enums.HouseStructureEnum;
import com.xiaoshuidi.cloud.framework.filings.core.enums.HouseTypeEnum;
import com.xiaoshuidi.cloud.framework.filings.core.enums.PropertyTypeEnum;
import com.xiaoshuidi.cloud.module.rooms.enums.TowardEnum;
import com.xiaoshuidi.cloud.module.rooms.utils.EnumUtil;


import java.util.Map;
/**
 * 房源导入校验父类
 * @Author Summer
 * @date 2023/5/22
 */
public abstract class AbstractHouseExcelImportValid<T> {
    public boolean  valid(T t,Map<String,String> errorMap) throws Exception{return true;}

    public boolean validHouseImportItem(String fieldName,Object fieldValue,Map<String,String> errorMap) throws Exception{
        //朝向
        if (fieldName.equals("toward")) {
            String toward = (String) fieldValue;
            if (!EnumUtil.isInclude(TowardEnum.class, "getName", toward)) {
                errorMap.put("toward", "朝向输入有误！");
                return false;
            }
        }

        //可住人数不超过5个人
        if (fieldName.equals("peopleNum")) {
            Integer peopleNum = (Integer) fieldValue;
            if (peopleNum > 10) {
                errorMap.put("peopleNum", "可住人数输入有误！");
                return false;
            }
        }
        //产权人证件类型
        if (fieldName.equals("cardType")) {
            String cardType = (String) fieldValue;
            if (!EnumUtil.isInclude(CodeTypeEnum.class, "getName", cardType)) {
                errorMap.put("toward", "产权人证件类型输入有误！");
                return false;
            }
        }
        //产权类型
        if (fieldName.equals("propertyType")) {
            String propertyType = (String) fieldValue;
            if (!EnumUtil.isInclude(PropertyTypeEnum.class, "getName", propertyType)) {
                errorMap.put("propertyType", "产权类型输入有误！");
                return false;
            }
        }

        //房屋类型
        if (fieldName.equals("registerType")) {
            String registerType = (String) fieldValue;
            if (!EnumUtil.isInclude(HouseTypeEnum.class, "getName", registerType)) {
                errorMap.put("registerType", "房屋类型输入有误！");
                return false;
            }
        }

        //房屋结构
        if (fieldName.equals("houseStructure")) {
            String houseStructure = (String) fieldValue;
            if (!EnumUtil.isInclude(HouseStructureEnum.class, "getName", houseStructure)) {
                errorMap.put("houseStructure", "房屋结构输入有误！");
                return false;
            }
        }


        //装修程度
        if (fieldName.equals("decoration")) {
            String decoration = (String) fieldValue;
            if (!EnumUtil.isInclude(DecorationLevelEnum.class, "getName", decoration)) {
                errorMap.put("decoration", "装修程度输入有误！");
                return false;
            }
        }
        return true;
    }

}
